using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;

namespace LevelEditor
{
    public class ScreenQuad
    {
        VertexPositionTexture[] vertecies;

        /// <summary>
        /// Gets or sets the area of the screen the rectangle will draw to in screen coordinates
        /// </summary>
        public Rectangle ScreenRect
        {
            get
            {
                int top = (int)vertecies[1].Position.Y;
                int bottom = (int)vertecies[0].Position.Y;
                int left = (int)vertecies[0].Position.X;
                int right = (int)vertecies[1].Position.X;

                return new Rectangle(top, left, right - left, bottom - top);
            }

            set
            {
                vertecies[0].Position = new Vector3(value.Left, value.Bottom, 0.0f);
                vertecies[1].Position = new Vector3(value.Left, value.Top, 0.0f);
                vertecies[2].Position = new Vector3(value.Right, value.Bottom, 0.0f);
                vertecies[3].Position = new Vector3(value.Right, value.Top, 0.0f);
            }
        }

        public ScreenQuad()
        {
            Init();
        }

        void Init()
        {

            vertecies = new VertexPositionTexture[4]
            {
                // 00
                new VertexPositionTexture(new Vector3(-1.0f, 0.999f, 0.0f),new Vector2(0.0f, 1.0f)),
                // 01
                new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 0.0f),new Vector2(0.0f, 0.0f)),
                // 10
                new VertexPositionTexture(new Vector3(0.999f, 0.999f, 0.0f), new Vector2(1.0f, 1.0f)),
                // 11
                new VertexPositionTexture(new Vector3(0.999f, -1.0f, 0.0f),new Vector2(1.0f, 0.0f)),
            };

        }

        public void Draw()
        {
            MainMenu.instance.graphics.device.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, vertecies, 0, 2);
        }
    }
}